package org.komarichin.beans.service;

import org.komarichin.beans.ILanguage;
import org.komarichin.beans.INews;

import java.io.Serializable;
import java.util.Collection;

/**
 * User: Michael Komarichin
 * Date: 14.10.2009
 * Time: 12:42:05
 */

public interface INewsService<PK> extends Serializable {

    /**
     * @param news saving news
     * @return saved news
     */
    INews<PK> save(INews<PK> news);

    /**
     * @param news news for update
     */
    void saveOrUpdate(INews<PK> news);

    /**
     * @param news news for remove
     */
    void remove(INews<PK> news);

    /**
     * @param id news's id
     */
    void remove(PK id);

    /**
     * @param id news id
     * @return news object or null
     */
    INews<PK> findById(PK id);

    /**
     * @return all news in bd
     */
    Collection<INews<PK>> getAll();

    /**
     * @param start     start result
     * @param limit     max returned result in query
     * @param fieldName field by sorting
     * @param order     sort order, true as asc, false as desc
     * @return result as news object by criteria
     */
    Collection<INews<PK>> getNews(int start, int limit, String fieldName, boolean order);

    /**
     * @return count of objects news, if result equals 1000 then truth count will be >= 1000
     */
    int getCountNews();

    /**
     * @return collection of latest entities sorted by date create
     */
    Collection<INews<PK>> getLatestNews();

    /**
     * @param lang language
     * @return collection of entities by language
     */
    Collection<INews<PK>> getAll(ILanguage<PK> lang);

    /**
     * @param lang      language
     * @param start     start , default = 0
     * @param limit     limit default 20
     * @param fieldName sorted field name
     * @param order     sorted order
     * @return collection of entities
     */
    Collection<INews<PK>> getNews(ILanguage lang, int start, int limit, String fieldName, boolean order);

    /**
     * @param lang language
     * @return count news by language
     */
    int getCountNews(ILanguage lang);

    /**
     * @param lang language
     * @return collection of latest entities by language
     */
    Collection<INews<PK>> getLatestNews(ILanguage lang);
}
